
app.controller('detailCtrl', function($scope) {
	
	 //***************数量操作
    $scope.detailCount=1;
      $scope.detailFun=function(){
      	console.log(111)
      	$scope.detailCount=$scope.detailCount-1
      	if($scope.detailCount==-1){
      		$scope.detailCount=0
      	}
      	
      }
	 //显示隐藏商品介绍
	  $scope.bol=true;
	  $scope.detailFun1=function(e){
	  	$scope.bol=!$scope.bol
	  	$('.g_detailEval span').removeClass('g_detailEvalAt')
	  	$(e.target).addClass('g_detailEvalAt')
	  	
	  }
	
    //放大镜
	$('.zoom').on('mouseenter', function(e) {
		$('.zoomL').show();
		$('.zoomB').show();
		var even = e || event;

		$('.zoom').on('mousemove', function(e) {
			var even = e || event;
			var lWidth = $('.zoomL').width();
			var lHeight = $('.zoomL').height();
			var imgWidth = $('.zoom img').width()
			var imgHeight = $('.zoom img').height();
			//获取移动框位置
			console.log(even.clientY)
			var x1 = even.pageX - $('.zoom').offset().left - 0.5 * lWidth
			var y1 = even.pageY - $('.zoom').offset().top - 0.5 * lHeight
				//限定移动框范围
			x1 <= 0 ? x1 = 0 : x1 = x1;
			x1 > (imgWidth - lWidth) ? x1 = (imgWidth - lWidth) : x1 = x1;
			y1 <= 0 ? y1 = 0 : y1 = y1;
			y1 > (imgHeight - lHeight) ? y1 = (imgHeight - lHeight) : y1 = y1;
			$('.zoomL').css({
				left: x1,
				top: y1
			})
			var zoomBW = $('.zoomB').width();
			var zoomBH = $('.zoomB').height();
			var zoomBImgW = $('.zoomB img').width();
			var zoomBImgH = $('.zoomB img').height();
			var x2 = x1 * (zoomBImgW - zoomBW) / (imgWidth - lWidth)
			var y2 = y1 * (zoomBImgH - zoomBH) / (imgHeight - lHeight)
			$('.zoomB')[0].scrollLeft = x2;
			$('.zoomB')[0].scrollTop = y2;

		})

	})
	$('.zoom').on('mouseleave', function() {

		$('.zoomL').hide();
		$('.zoomB').hide();
	})

	//图片预览
	$('.g_detailGose_Limg img').each(function(i, e) {

		$(e).on('click', function() {
			var imgUrl = $(e).attr('src');
			$('.g_detailMT img').eq(0).attr('src', imgUrl)
			$('.g_detailMT').show();
		})
	})
	$('.g_detailMT img').eq(1).on('click', function() {
		$('.g_detailMT').hide();
	})

    //获取选择
    $('.g_detailGose_RFt4').each(function(index,el){
    	    $(el).on('click',function(){
    	    	if(index<3){
    	    		 $('.g_detailGose_RFt4').eq(0).removeClass('g_detailAt')
    	    		 $('.g_detailGose_RFt4').eq(1).removeClass('g_detailAt')
    	    		 $('.g_detailGose_RFt4').eq(2).removeClass('g_detailAt')
      	    $(this).addClass('g_detailAt')
      	    
      	    
    	    	}else{
    	    		$('.g_detailGose_RFt4').eq(3).removeClass('g_detailAt')
    	    		 $('.g_detailGose_RFt4').eq(4).removeClass('g_detailAt')
    	    		 $('.g_detailGose_RFt4').eq(5).removeClass('g_detailAt')
      	    $(this).addClass('g_detailAt')
    	    		
    	    	}
      	 
        })
    })
    
   
   




})